<%
/**
 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
%>

<%@ include file="/html/portlet/communities/init.jsp" %>

<%
String redirect = ParamUtil.getString(request, "redirect");

Group group = (Group)request.getAttribute(WebKeys.GROUP);
CommunityExtra communityExtra = null;
int type_ = 1;
int category = 1;
if(Validator.isNotNull(group)){
	 communityExtra = CommunityExtraLocalServiceUtil.getCommunityByGroupId(group.getGroupId());
		if(Validator.isNotNull(communityExtra)){
	 		type_ = communityExtra.getType();
	 		category = communityExtra.getCategory();
	 	}
}			

long groupId = BeanParamUtil.getLong(group, request, "groupId");

int type = BeanParamUtil.getInteger(group, request, "type");

String friendlyURL = BeanParamUtil.getString(group, request, "friendlyURL");
%>

<script type="text/javascript">
	function <portlet:namespace />saveGroup() {
		document.<portlet:namespace />fm.<portlet:namespace /><%= Constants.CMD %>.value = "<%= group == null ? Constants.ADD : Constants.UPDATE %>";
		submitForm(document.<portlet:namespace />fm);
	}
</script>

<form action="<portlet:actionURL windowState="<%= WindowState.MAXIMIZED.toString() %>"><portlet:param name="struts_action" value="/communities/edit_community" /></portlet:actionURL>" method="post" name="<portlet:namespace />fm" onSubmit="<portlet:namespace />saveGroup(); return false;">
<input name="<portlet:namespace /><%= Constants.CMD %>" type="hidden" value="" />
<input name="<portlet:namespace />redirect" type="hidden" value="<%= HtmlUtil.escape(redirect) %>" />
<input name="<portlet:namespace />groupId" type="hidden" value="<%= groupId %>" />
<input name="<portlet:namespace />friendlyURL" type="hidden" value="<%= friendlyURL %>" />

<liferay-util:include page="/html/portlet/communities/toolbar.jsp">
	<liferay-util:param name="toolbarItem" value='<%= (group == null) ? "add" : "view-all" %>' />
</liferay-util:include>

<liferay-ui:error exception="<%= DuplicateGroupException.class %>" message="please-enter-a-unique-name" />
<liferay-ui:error exception="<%= GroupNameException.class %>" message="please-enter-a-valid-name" />
<liferay-ui:error exception="<%= RequiredGroupException.class %>" message="old-group-name-is-a-required-system-group" />

<table class="lfr-table">

<c:if test="<%= group != null %>">
	<tr>
		<td class="lfr-label">
			<liferay-ui:message key="group-id" />
		</td>
		<td>
			<%= groupId %>
		</td>
	</tr>
</c:if>

<tr>
	<td class="lfr-label">
		<liferay-ui:message key="name" />
	</td>
	<td>
		<liferay-ui:input-field model="<%= Group.class %>" bean="<%= group %>" field="name" />
	</td>
</tr>
<tr>
	<td class="lfr-label">
		<liferay-ui:message key="description" />
	</td>
	<td>
		<liferay-ui:input-field model="<%= Group.class %>" bean="<%= group %>" field="description" />
	</td>
</tr>
<tr>
	<td class="lfr-label">
		<liferay-ui:message key="Category" />
	</td>
	<td>
		<select name="<portlet:namespace />category">
			<option <%= (category == 1) ? "selected" : "" %> value="1"><liferay-ui:message key="Common" /></option>
			<option <%= (category == 2) ? "selected" : "" %> value="2"><liferay-ui:message key="Academic" /></option>
			<option <%= (category == 3) ? "selected" : "" %> value="3"><liferay-ui:message key="Social" /></option>
		</select>
	</td>
</tr>
<tr>
	<td class="lfr-label">
		<liferay-ui:message key="type" />
	</td>
	<td>
		<select name="<portlet:namespace />type_">
			<option <%= (type_ == 1) ? "selected" : "" %> value="1"><liferay-ui:message key="School" /></option>
			<option <%= (type_ == 2) ? "selected" : "" %> value="2"><liferay-ui:message key="College" /></option>
			<option <%= (type_ == 3) ? "selected" : "" %> value="3"><liferay-ui:message key="Mainstay" /></option>
			<option <%= (type_ == 4) ? "selected" : "" %> value="4"><liferay-ui:message key="Benchmark" /></option>
			<option <%= (type_ == 5) ? "selected" : "" %> value="5"><liferay-ui:message key="Benchmark School" /></option>
			<option <%= (type_ == 6) ? "selected" : "" %> value="6"><liferay-ui:message key="Benchmark College" /></option>
			<option <%= (type_ == 7) ? "selected" : "" %> value="7"><liferay-ui:message key="Benchmark Mainstay" /></option>		
		</select>
	</td>
</tr>
<tr>
	<td class="lfr-label">
		<liferay-ui:message key="type" />
	</td>
	<td>
		<select name="<portlet:namespace />type">
			<option <%= (type == GroupConstants.TYPE_COMMUNITY_OPEN) ? "selected" : "" %> value="<%= GroupConstants.TYPE_COMMUNITY_OPEN %>"><liferay-ui:message key="open" /></option>
			<option <%= (type == GroupConstants.TYPE_COMMUNITY_RESTRICTED) ? "selected" : "" %> value="<%= GroupConstants.TYPE_COMMUNITY_RESTRICTED %>"><liferay-ui:message key="restricted" /></option>
			<option <%= (type == GroupConstants.TYPE_COMMUNITY_PRIVATE) ? "selected" : "" %> value="<%= GroupConstants.TYPE_COMMUNITY_PRIVATE %>"><liferay-ui:message key="private" /></option>
		</select>
	</td>
</tr>
<tr>
	<td class="lfr-label">
		<liferay-ui:message key="active" />
	</td>
	<td>
		<liferay-ui:input-field model="<%= Group.class %>" bean="<%= group %>" field="active" defaultValue="<%= Boolean.TRUE %>" />
	</td>
</tr>
</table>

<br />

<input type="submit" value="<liferay-ui:message key="save" />" />

<input type="button" value="<liferay-ui:message key="cancel" />" onClick="location.href = '<%= HtmlUtil.escape(redirect) %>';" />

</form>

<c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
	<script type="text/javascript">
		Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace />name);
	</script>
</c:if>